# -*- coding: utf-8 -*-
# @Time : 2022/6/22 22:36
# @Author : cheney
# @File : steeringDao.py
# @Software: PyCharm
# @Site: www.cheney.cc

"""
    舵机模块 + 超声波模块
"""
from pi.dao.steeringDao import steeringDao
from pi.dao.ultrasonicDao import ultrasonicDao
import time
import sys


class ultrasonicServoController:
    steerDao = steeringDao()
    ultrDao = ultrasonicDao()
    sleep_time = None

    def __init__(self, sleep_time=0.5):
        self.sleep_time = sleep_time

    def scan_left(self) -> float:
        self.steerDao.write(0, 175, sleep_time=self.sleep_time)
        return self.ultrDao.get_distance()

    def scan_right(self) -> float:
        self.steerDao.write(0, 5, sleep_time=self.sleep_time)
        return self.ultrDao.get_distance()

    def scan_front(self) -> float:
        self.steerDao.write(0, 90, sleep_time=self.sleep_time)
        return self.ultrDao.get_distance()


if __name__ == '__main__':
    steerCon = ultrasonicServoController(2)
    while True:
        print(steerCon.scan_left())
        print(steerCon.scan_front())
        print(steerCon.scan_right())
